/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.diamondsys.embrapa;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Rafael
 */
@Stateless
public class ProfissaoFormacaoFacade extends AbstractFacade<ProfissaoFormacao> {
    @PersistenceContext(unitName = "com.diamondsys_embrapa_war_1.0-SNAPSHOTPU")
    private EntityManager em;

    /**
     *
     * @return
     */
    @Override
    public EntityManager getEntityManager() {
        return em;
    }

    /**
     *
     */
    public ProfissaoFormacaoFacade() {
        super(ProfissaoFormacao.class);
    }
    
    @Override
    public List<ProfissaoFormacao> findAll() {
        return em.createNamedQuery("ProfissaoFormacao.findAll", ProfissaoFormacao.class).getResultList();
    }       

    public List<ProfissaoFormacao> findAllProffisao() {
        return em.createQuery("SELECT p FROM ProfissaoFormacao p WHERE COALESCE(p.profissao, 'S') = 'S' ORDER BY p.descricao", ProfissaoFormacao.class).getResultList();
    }   
    
    public List<ProfissaoFormacao> findAllFormacao() {
        return em.createQuery("SELECT p FROM ProfissaoFormacao p WHERE COALESCE(p.profissao, 'N') = 'N' ORDER BY p.descricao", ProfissaoFormacao.class).getResultList();
    }       

    public ProfissaoFormacao findByName(String name,char proffisao) {

        try
        {
            return em.createQuery("SELECT p FROM ProfissaoFormacao p WHERE p.profissao = :profissao AND p.descricao = :descricao", ProfissaoFormacao.class)
                    .setParameter("profissao", proffisao)
                    .setParameter("descricao", name)
                    .getSingleResult();
        }
        catch(NoResultException ex)
        {
            return null;
        }
    }      
    
}
